define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'service/proposal/index' + location.search,
                    add_url: 'service/proposal/add',
                    edit_url: 'service/proposal/edit',
                    del_url: 'service/proposal/del',
                    multi_url: 'service/proposal/multi',
                    import_url: 'service/proposal/import',
                    table: 'proposal',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {
                            field: 'type',
                            title: '反馈类型',
                            searchList: {1: '优化建议', 2: '问题反馈', 3: '投诉', 4: '车辆申诉'},
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'content', title: "反馈内容"},
                        {
                            field: 'image',
                            title: '证明图片',
                            operate: false,
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.image
                        },
                        {
                            field: 'code',
                            title: '验证码',
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'mobile',
                            title: '联系电话',
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        },
                        {
                            field: 'operate',
                            title: "申诉通知",
                            table: table,
                            events: Table.api.events.operate,
                            formatter: function (value, row, index) {
                                if (row.type == "4") {
                                    if (row.is_notice == '1') {
                                        return "<div style='color: green'>已通知</div><button onclick='tongzhi(" + row.id + ")'   class='shenhe btn-success'>申诉通知</button>"
                                    }
                                    return "<div style='color: red'>未通知</div><button onclick='tongzhi(" + row.id + ")'   class='shenhe btn-success'>申诉通知</button>"
                                }
                            }
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});

function tongzhi(id) {
    layer.open({
        type: 1,
        title: '申诉通知',
        content: $('#popup'),
        area: ['500px', '300px']
    });
    $("#id").val(id)
}

$("#tongzhipost").click(function () {
    let type = $("#c-type").val()
    let info = $("#c-info").val()
    let id = $("#id").val()
    layer.confirm(`确定该操作吗？`, {
            title: "申诉通知",
            btn: ['确定', '取消'] //按钮
        }, function (index) {
            $.ajax({
                url: "service/proposal/results", //请求接口
                type: "post",
                dataType: "json",
                data: {
                    "id": id,
                    "type": type,
                    "info": info
                }, //请求参数
                success: function (data) {
                    layer.confirm(data.msg, {
                        btn: ['确定'] //按钮
                    }, function (index2) {
                        Fast.api.refreshmenu(); //刷新列表
                        layer.closeAll(); //关闭窗口
                    })
                    return false;
                }
            })

        }
    );

})
